<?php
namespace app\model\admin;

use think\Db;

class Article
{
    //获取文章列表
    public function get_article_lists($where,$sort='',$paginate=10)
    {
        $join = [
            ['lh_column b','a.column=b.id'],
        ];
        $result_lists = Db::name('article')->alias('a')->where($where)->join($join)->field('a.id,a.title,a.content,a.read_num,a.seo_name_en,b.seo_name_en as c_seo_name,a.add_time,b.name')->order($sort)->paginate($paginate);
        return $result_lists;
    }

    //获取文章列表-between条件
    public function get_article_lists_between($where,$between='',$sort='',$paginate=10)
    {
        if(empty($between))return false;
        $result_lists = Db::name('article')->where($where)->where($between['val'],'between','"'.$between['one'].'","'.$between['two'].'"')->order($sort)->paginate($paginate);
        return $result_lists;
    }

    //文章详情
    public function article_detail($article_id){
        $result = Db::name('article')->where('id',$article_id)->find();
        return $result;
    }

    //文章添加
    public function add_article($data){
        $status = Db::name('article')->insertGetId($data);
        return $status;
    }

    //文章修改
    public function update_article($where,$data){
        $status = Db::name('article')->where($where)->update($data);
        return $status;
    }

    //文章删除
    public function delete_article($array_id){
        $article_delete = Db::name('article')->delete($array_id);
        return $article_delete;
    }

    //获取文章数量
    public function get_article_num($where){
        $result = Db::name('article')->where($where)->count();
        return $result;
    }


}


